package com.wr.config;

import com.wr.service.SessionService;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

/**
 * @author WuRui
 * @Date 2017/5/22 0022
 */
@Component
public class MyApplicationContext implements ApplicationContextAware {

    @Override
    public void setApplicationContext(ApplicationContext _applicationContext) throws BeansException {
        SessionService sessionService = (SessionService) myApplicationContext(_applicationContext,SessionService.class);
        sessionService.deleteAll();
    }

    private static Object myApplicationContext(ApplicationContext _applicationContext, Class cl){
        Object t = _applicationContext.getBean(cl);
        return t;
    }
}
